package com.sgb.member.ui.adapter;

import android.app.Activity;
import android.content.Intent;
import android.icu.text.DecimalFormat;
import android.icu.text.SimpleDateFormat;
import android.net.Uri;
import android.os.Build;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.sgb.member.BR;
import com.sgb.member.MemberConfig;
import com.sgb.member.R;
import com.sgb.member.databinding.ItemOtherLogistics1Binding;
import com.sgb.member.databinding.ItemOtherLogisticsBinding;
import com.sgb.member.entity.MemberLogisticsEntity;
import com.sgb.member.entity.WuLiuCompanyBean;
import com.sgb.member.util.MCargoConstant;
import com.sgb.member.util.MVehicleConstant;
import com.sgb.member.weight.MemberCallback;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.MToast;
import com.swgk.core.util.NumberUtil;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.util.StringUtil;

import java.util.Date;
import java.util.List;

/**
 * 物流货运-会员货运
 *
 * @param <T>
 */
public class WuLiuMemberAdapter<T> extends BaseRecycleAdapter<T> {

    MemberCallback memberCallback;

    public WuLiuMemberAdapter(Activity activity, int layoutId, List<T> datas) {
        super(activity, layoutId, datas);
    }

    public WuLiuMemberAdapter(Activity activity, int layoutId, List<T> datas, MemberCallback memberCallback) {
        super(activity, layoutId, datas);
        this.memberCallback = memberCallback;
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void convert(ItemViewHolder holder, final T t) {
        logisticsGoods(holder, t);
    }

    private WuliuOperate operate;
    public void setWuliuOperate(WuliuOperate operate) {
        this.operate = operate;
    }


    // 物流货物 -会员货运
    @RequiresApi(api = Build.VERSION_CODES.N)
    private void logisticsGoods(ItemViewHolder holder, T t) {
        holder.setBinding(BR.viewModel, t);
        WuLiuCompanyBean entity = (WuLiuCompanyBean) t;
        ItemOtherLogistics1Binding binding = (ItemOtherLogistics1Binding) holder.getmBinding();
        binding.tvGoods.setText(entity.getCityName()+" "+entity.getDistrictName()
                +" → "+entity.getDestCityName()+" "+ entity.getDestDistrictName());
        binding.tvDistance.setText(Double.parseDouble(entity.getTotalDistance())/1000+"km");

        binding.typeName.setText(entity.getCarModelName()+"/"+entity.getCarLenName());

        if( entity.getFreightType()==1){
            binding.tvYunFei.setText("运费电议");
        }else {
            binding.tvYunFei.setText("运费："+entity.getFreight()+"元");
        }
        binding.loadType.setText(entity.getGoodsModeName()+"/"+entity.getWeight()+"吨"+"/"
        +entity.getPackingModeName()+"/"+entity.getHandleName());

        SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd");
        Long time =entity.getShipmentEndTime();
        Long time_end =entity.getShipmentEndTime();
        Date date = new Date(time);
        Date date1 = new Date(time_end);
        binding.loadTime.setText(dateFormat.format(date)+"全天-"+dateFormat.format(date1)+"全天 装货");
       if(entity.getLowestPrice()==0.0){
           binding.tvLowerPrice.setText("/");
       }else {
           DecimalFormat df = new DecimalFormat("#.00");
           binding.tvLowerPrice.setText(df.format(entity.getLowestPrice())+"元");
       }
        String loadTypeStr = MCargoConstant.getTransportTypeStr(entity.getTransportType());
        if (loadTypeStr.equals("零担")) {
            binding.tip.setVisibility(View.VISIBLE);
            binding.tip.setImageResource(R.mipmap.member_icon_less_than_tag);
        } else if (loadTypeStr.equals("整车")) {
            binding.tip.setVisibility(View.VISIBLE);
            binding.tip.setImageResource(R.mipmap.member_all_cart);
        } else {
            binding.tip.setVisibility(View.GONE);
        }

        binding.tvPeopleNum.setText(entity.getOfferNum()+"");
        binding.tvNum2.setText(entity.getOfferNum()+"");
        binding.tvNum3.setText(entity.getInquiryNum()+"");
        binding.tv1.setOnClickListener(v -> operate.apply(entity));
        binding.tv2.setOnClickListener(v -> {
            operate.baoJia( entity);
        });
        binding.tv3.setOnClickListener(v ->operate.hanxun(entity));
        binding.tv4.setOnClickListener(v ->operate.xiaDan(entity));
        binding.map.setOnClickListener(v -> operate.map(entity));
    }

    public interface WuliuOperate{
        void apply(WuLiuCompanyBean entity);//车主申请
        void baoJia(WuLiuCompanyBean entity);//车主报价
        void hanxun(WuLiuCompanyBean entity);//函询
        void xiaDan(WuLiuCompanyBean entity);//下单
        void map(WuLiuCompanyBean entity);
    }


}
